# Build recipe for gettext-tiny.
#
# Copyright (c) 2017 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=gettext-tiny
version=0.2.0
release=1

# The installation of this package replaces
replace=gettext

tarname=${program}-${version}.tar.xz

# Remote source(s)
fetch=http://ftp.barfooze.de/pub/sabotage/tarballs/$tarname

description="
Lightweight replacements for tools used in the GNU gettext.

gettext-tiny provides lightweight replacements for tools typically used
from the GNU gettext suite, which is incredibly bloated and takes a lot
of time to build (in the order of an hour on slow devices).  The most
notable component is msgfmt which is used to create binary translation
files in the .mo format out of textual input files in .po format.
This is the most important tool for building software from source,
because it is used from the build processes of many software packages.
"

homepage=http://github.com/sabotage-linux/gettext-tiny
license=MIT

# Source documentation
docs="LICENSE README.md"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    make -j${jobs} V=1 \
     CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" LIBINTL=MUSL \
     prefix=/usr libdir=/usr/lib${libSuffix} DESTDIR="$destdir" install

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}"
}

